// function useState(initState: number): [number, (newState: number) => void] {
//   let state = initState;
//   function setState(newState: number) {
//     state = newState;
//   }
//   return [state, setState];
// }

function useState<T>(initState: T): [T, (newState: T) => void] {
  let state = initState;
  function setState(newState: T) {
    state = newState;
  }
  return [state, setState];
}

// const [count, setCount] = useState(100);
const [count, setCount] = useState<any[]>([]);

//泛型接口
interface IKun<T1, T2> {
  name: T1;
  age: T2;
}
const kunk: IKun<string, number> = {
  name: "123",
  age: 12,
};

//泛型类
// class Point<T> {
//   x: T;
//   y: T;
//   constructor(x: T, y: T) {
//     this.x = x;
//     this.y = y;
//   }
// }
class Point<T> {
  constructor(public x: T, public y: T) {}
}

//泛型约束
class Point2<T extends IKun<T, T>> {
  constructor(public x: T, public y: T) {}
}

interface obje {
  name: string;
  age: number;
}

type kes_of_o = keyof obje; //kes_of_o 为obje key的联合类型 联合类型

function getObjectProperty<O, K extends keyof O>(obj: O, key: K) {
  return obj[key];
}
getObjectProperty({ name: "marvin" }, "name");
// getObjectProperty({ name: "marvin" }, "age"); //报错

interface IPerson {
  name: string;
  readonly age: number;
  height?: number;
}
//映射类型
//拷贝一份IPerson
type MapPerson<T> = {
  [prop in keyof T]: T[prop]; //遍历
};

type MapPerson2<T> = {
  readonly [prop in keyof T]?: T[prop]; //遍历
};

type MapPerson3<T> = {
  -readonly [prop in keyof T]-?: T[prop]; //遍历
};

type NewPerson = MapPerson<IPerson>;
type NewPerson2 = MapPerson2<IPerson>;
type NewPerson3 = MapPerson3<IPerson>;

export {};
